/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package v;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Usuario
 */
public class Borrarme {
    public static void main(String[] args){
//        String cadena = "[idinicio] integer NOT NULL, [Tipo] [varchar](20) NOT NULL,[lEnabled] [bit] NOT NULL,	[nHeight] [smallint] NOT NULL,	[nLeft] [smallint] NOT NULL,	[cName] [varchar](50) NOT NULL,	[nTabIndex] [smallint] NOT NULL,	[cToolTipText] [varchar](50) NOT NULL,	[nTop] [smallint] NOT NULL,	[lVisible] [bit] NOT NULL,	[nWidth] [smallint] NOT NULL,	[nMaxLength] [smallint] NOT NULL,	[cValue] [varchar](50) NOT NULL,	[cControlSource] [varchar](50) NOT NULL,	[cRowSource] [varchar](50) NOT NULL,	[nRowSourceType] [smallint] NOT NULL,	[nColumnCount] [smallint] NOT NULL,	[cCaption] [varchar](50) NOT NULL,	[lAutoSize] [bit] NOT NULL,	[cText] [varchar](500) NOT NULL,	[lReadOnly] [bit] NOT NULL,	[filtro] [varchar](100) NULL,	CONSTRAINT [PK_controles] PRIMARY KEY (idControles),	CONSTRAINT [FK_controles_inicio] FOREIGN KEY([idinicio])	REFERENCES inicio ([idinicio]))";
//        String cadena2 = cadena.replaceAll("\\[", "");
//        cadena2 = cadena2.replaceAll("\\]", "");
//        System.out.println(cadena2);

        Map<String, String> mapa = new HashMap<String, String>();
        
        for(int i =0; i <5; i ++){
            mapa.put("atrib" + i, "valor"+i);
        }
        
        System.out.println(getInsert(mapa));
        System.out.println("Fecha interes: " + esCitaModificable("2012-07-20", "12:00:00"));
        
        String[] joder = {"cad1", "test1", "unn"};
        
        System.out.println(concatenaArray(joder));
    }
    
    public static String getInsert(Map<String, String> mapa){
        
        Iterator it = mapa.entrySet().iterator();
        String result = "INSERT INTO table(";
        String values = " VALUES(";
        while(it.hasNext()){
            Map.Entry<String, String> pair = (Map.Entry<String, String>) it.next();
            result += String.format("\"%s\"", pair.getKey());
            values += String.format("'%s'", pair.getValue());
            if(it.hasNext()){
                result += ", ";
                values += ", ";
            }
        }
        result += ")";
        values += ");";
        return result + values;
    }
    
    public static String removeCharAt(String s, int pos) {
        StringBuffer buf = new StringBuffer(s.length() - 1);
        buf.append(s.substring(0, pos)).append(s.substring(pos + 1));
        return buf.toString();
    }
    
    public static Boolean esCitaModificable(String fecha, String hora) {
        SimpleDateFormat s = new SimpleDateFormat("yy-MM-dd kk:mm");
        String test = fecha + " " + hora;
        Date result = new Date();
        Date compa = new Date();
        
        try {
            result = s.parse(test);
        } catch (ParseException ex) {
            Logger.getLogger(Borrarme.class.getName()).log(Level.SEVERE, null, ex);
        }
        return !(result.before(compa));
    }
    
    private static String concatenaArray(String[] array){
        StringBuilder result = new StringBuilder();
        
        int n = array.length;
        
        for(int i = 0; i < n; i++){
            result.append(array[i]);
            if(i < (n -1)){
                result.append(", ");
            }
        }
        
        return result.toString();
    }
}